package com.xcity.pomelo.push.msg;

import com.xcity.db.entity.Player;
import com.xcity.game.common.Currency;
import com.xcity.game.shop.ShopItemTemplate;
import com.xcity.pomelo.PomeloRoute;
import com.xcity.pomelo.push.AbstractMessagePush;

import naga.x.App;
import naga.x.game.template.TemplateService;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.PUSH, route = PomeloRoute.PUSH_MESSAGE)
public class BuyTipPush extends AbstractMessagePush {

	private int id;
	private String name;
	private String icon;
	private long price;
	private Currency type;
	private int maxCount;
	
	public BuyTipPush(Player player, int itemId) {
		this(player, App.getApp().getServiceManager().get(TemplateService.class).get(ShopItemTemplate.class, itemId));
	}
	
	public BuyTipPush(Player player, ShopItemTemplate shopItem) {
		super(MSG_BUY_TIP);
		this.id = shopItem.getId();
		this.name = shopItem.getName();
		this.icon = shopItem.getIcon();
		this.price = shopItem.getPrice();
		this.type = shopItem.getPriceType();
		this.maxCount = (int) ((this.type == Currency.GOLD ? player.getGold() : player.getStone()) / this.price);
		// 检测背包最多能放多少该物品
		int max = player.getBag().getFreeSize() * shopItem.getItem().getStack();
		if (this.maxCount > max) {
			this.maxCount = max;
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public int getMaxCount() {
		return maxCount;
	}

	public void setMaxCount(int maxCount) {
		this.maxCount = maxCount;
	}

	public long getPrice() {
		return price;
	}

	public void setPrice(long price) {
		this.price = price;
	}

	public Currency getType() {
		return type;
	}

	public void setType(Currency type) {
		this.type = type;
	}

	
}
